﻿/*
 * This software is the confidential and proprietary
 * information of NetBay
 * Such confidential information should not be disclosed
 * NetBay copyright(c) 2010
 */

#region Using

using System;
using System.Collections.Generic;
using NetBay.Core.BusinessEntities;
using System.Data;
using NetBay.Core.Extensions;

#endregion

namespace Rio.Doc.Business.Repository.Translator
{
    /// <summary>
    /// Class used to convert Group database row to Group object
    /// </summary>
    public class FolderTypeRightsTranslator
    {
        /// <summary>
        /// Translate a bunch of Group DataReader to Group object
        /// </summary>
        /// <param name="DbDataReader">The dataReader that contains the rows</param>
        /// <returns>A list of Group Object</returns>
        public static List<FolderTypeRights> TranslateFolderTypeRights(IDataReader DbDataReader)
        {
            //Variable initialization
            var l_lstGroups = new List<FolderTypeRights>();

            try
            {
                using (DbDataReader)
                {
                    while (DbDataReader.Read())
                    {
                        var l_oGroup = new FolderTypeRights();

                        l_oGroup.Identifier = DbDataReader.GetLongValue("RG_ID");
                        l_oGroup.IsAdministrator = DbDataReader.GetBooleanValue("ADMINISTRATE");
                        if (l_oGroup.IsAdministrator)
                        {
                            l_oGroup.CanConsult = true;
                            l_oGroup.CanConsultExtended = true;
                            l_oGroup.CanScann = true;
                            l_oGroup.CanScanExtended = true;
                            l_oGroup.CanReorganize = true;
                            l_oGroup.CanPrint = true;
                            l_oGroup.CanDownload = true;
                            l_oGroup.CanSendEmail = true;
                            l_oGroup.CanAnnotate = true;
                            l_oGroup.CanDelete = true;
                            l_oGroup.CanTrash = true;
                        }
                        else
                        {

                            l_oGroup.CanConsult =
                                DbDataReader.GetBooleanValue("CONSULT");
                            l_oGroup.CanConsultExtended =
                                DbDataReader.GetBooleanValue("CONSULTEXTENDED");
                            l_oGroup.CanScann =
                                DbDataReader.GetBooleanValue("ACQUIRE");
                            l_oGroup.CanScanExtended =
                                DbDataReader.GetBooleanValue("ACQUIREEXTENDED");
                            l_oGroup.CanReorganize =
                                DbDataReader.GetBooleanValue("UPDATE");
                            l_oGroup.CanPrint =
                                DbDataReader.GetBooleanValue("PRINT");
                            l_oGroup.CanDownload =
                                DbDataReader.GetBooleanValue("DOWNLOAD");
                            l_oGroup.CanSendEmail =
                                DbDataReader.GetBooleanValue("SENDMAIL");
                            l_oGroup.CanAnnotate =
                                DbDataReader.GetBooleanValue("ANNOTATE");
                            l_oGroup.CanDelete =
                                DbDataReader.GetBooleanValue("REMOVE");
                            l_oGroup.CanTrash = DbDataReader.GetBooleanValue("TRASH");
                        }


                        l_oGroup.FolderType =
                            FolderTypeRepository.GetFolderTypeById(DbDataReader.GetLongValue("rp_td_id"));
                        l_oGroup.Organization =
                            OrganizationRepository.GetOrganizationId(DbDataReader.GetLongValue("re_id"));


                        l_lstGroups.Add(l_oGroup);
                    }
                }
            }
            catch (Exception ex)
            {
                NetBay.Core.Log.LogManager.Instance().LogError(NetBay.Core.Diagnostics.Method.GetMethodBaseName(NetBay.Core.Diagnostics.Method.Level.Father) + " EXCEPTION -> " + Environment.NewLine + ex);
            }

            return l_lstGroups;
        }

    } 
}
